/****************************************************************************
 *  _____       ______  _____
 * |_   _|     |  ____|/ ____|
 *   | |  _ __ | |__  | (___    Institute of Embedded Systems
 *   | | | '_ \|  __|  \___ \   Zürcher Hochschule für Angewandte
 *  _| |_| | | | |____ ____) |  Wissenschaften
 * |_____|_| |_|______|_____/   8401 Winterthur, Switzerland
 *
 ****************************************************************************
 *
 * @version $Rev: 212 $
 * @author  $Author: bacr $
 * @date    $Date: 2014-01-10 14:09:50 +0100 (ven., 10 janv. 2014) $
 *
 ***************************************************************************/

#ifndef __HCPP_CONFIG_H__
#define __HCPP_CONFIG_H__

#define USE_AVALON_REGISTER_USER0                           0
#define USE_AVALON_DATA_CHECK                               0
#define USE_AVALON_BUS_WAIT                         0       /**< NIOS2 system clock = 125 MHz = 8 ns per instruction (nop) */
#define AVALON_BUS_WAIT_TIME                        125     /**< 125 x 8 ns = 1 us */

#define DELAY_RESP_TO_ALL                           true
#define USE_INTERNAL_CLOCK                          true
#define RX_DELAY                                    8200 /*8800*/
#define TX_DELAY                                    125  /*1000*/

/* PTPv2 port default values */
#define PTP2_PORT_IP_USE_DHCP                       0

#ifdef __NIOS2__
#define PTP2_PORT_IPV4_ADDRESS                              10,41,10,10
#define PTP2_PORT_IPV4_NETMASK                      255,255,0,0
#define PTP2_PORT_IPV4_GATEWAY                              10,41,10,10
#define PTP2_PORT_IPV6_ADDRESS                      1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
#define PTP2_PORT_MAC_ADDRESS                       0xaa,0xbb,0xcc,0xdd,0xee,0xff
#else
#define PTP2_PORT_IPV4_ADDRESS                      10,41,0,2
#define PTP2_PORT_IPV4_NETMASK                      255,255,0,0
#define PTP2_PORT_IPV4_GATEWAY                      10,41,0,2
#define PTP2_PORT_IPV6_ADDRESS                      1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
#define PTP2_PORT_MAC_ADDRESS                       0x00,0x1b,0x21,0x5c,0x22,0x01
#endif

#define PTP2_PORT_MULTICAST_ADDRESS_TYPE                    PTP2_ADDRESS_IPV4

#define PTP2_PORT_MULTICAST_IPV4_COUNT                      2
#define PTP2_PORT_MULTICAST_IPV4_PRIMARY_IP                 224,0,1,129
#define PTP2_PORT_MULTICAST_IPV4_PDELAY_IP                  224,0,0,107

#define PTP2_PORT_MULTICAST_IPV6_COUNT                      2
#define PTP2_PORT_MULTICAST_IPV6_PRIMARY_IP                 0xff0e,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0181
#define PTP2_PORT_MULTICAST_IPV6_PDELAY_IP                  0xff02,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x006b

#define PTP2_PORT_MULTICAST_MAC_COUNT               4
#define PTP2_PORT_MULTICAST_IPV4_PRIMARY_MAC                0x01,0x00,0x5e,0x00,0x01,0x81
#define PTP2_PORT_MULTICAST_IPV4_PDELAY_MAC                 0x01,0x00,0x5e,0x00,0x00,0x6b
#define PTP2_PORT_MULTICAST_IPV6_PRIMARY_MAC                0x33,0x33,0x00,0x00,0x01,0x81   /* not used */
#define PTP2_PORT_MULTICAST_IPV6_PDELAY_MAC                 0x33,0x33,0x00,0x00,0x00,0x6b   /* not used */
#define PTP2_PORT_MULTICAST_ETHER_PRIMARY_MAC               0x01,0x1b,0x19,0x00,0x00,0x00
#define PTP2_PORT_MULTICAST_ETHER_PDELAY_MAC                0x01,0x80,0xc2,0x00,0x00,0x0e

/* PTPv2 default dataset default values */
#define PTP2_DEFAULT_DS_TWO_STEP_CLOCK                      false
#define PTP2_DEFAULT_DS_CLOCK_IDENTITY                      0xaa,0xbb,0xcc,0xff,0xfe,0xdd,0xee,0xff
#define PTP2_DEFAULT_DS_PORT_COUNT                          1
#define PTP2_DEFAULT_DS_CLOCK_CLASS                         0x06
#define PTP2_DEFAULT_DS_CLOCK_ACCURACY                      0x20
#define PTP2_DEFAULT_DS_PRIORITY1                           0x05
#define PTP2_DEFAULT_DS_PRIORITY2                           0x01
#define PTP2_DEFAULT_DS_DOMAIN_NUMBER                       0
#define PTP2_DEFAULT_DS_SLAVE_ONLY                          false
#define PTP2_DEFAULT_DS_UNICAST_MODE                        true

/* PTPv2 time properties dataset default values */
#define PTP2_TIME_PROPERTIES_DS_CURRENT_UTC_OFFSET          35      /* TAI is ahead of UTC, in seconds */
#define PTP2_TIME_PROPERTIES_DS_CURRENT_UTC_OFFSET_VALID    true
#define PTP2_TIME_PROPERTIES_DS_LEAP59                      false
#define PTP2_TIME_PROPERTIES_DS_LEAP61                      false
#define PTP2_TIME_PROPERTIES_DS_TIME_TRACEABLE              true
#define PTP2_TIME_PROPERTIES_DS_FREQUENCY_TRACEABLE         true
#define PTP2_TIME_PROPERTIES_DS_PTP_TIMESCALE               true
#define PTP2_TIME_PROPERTIES_DS_TIME_SOURCE                 PTP2_TIME_SOURCE_INTERNAL_OSCILLATOR

/* PTPv2 port dataset default values */
#define PTP2_PORT_DS_PORT_NUMBER                    1
#define PTP2_PORT_DS_PORT_STATE                             PTP2_PORT_STATE_LISTENING
#define PTP2_PORT_DS_LOG_MIN_DELAY_REQ_INTERVAL             4
#define PTP2_PORT_DS_PEER_MEAN_PATH_DELAY                   0
#define PTP2_PORT_DS_LOG_ANNOUNCE_INTERVAL          1
#define PTP2_PORT_DS_ANNOUNCE_RECEIPT_TIMEOUT       3
#define PTP2_PORT_DS_FOREIGN_MASTER_THRESHOLD               2
#define PTP2_PORT_DS_FOREIGN_MASTER_TIME_WINDOW             4
#define PTP2_PORT_DS_LOG_SYNC_INTERVAL              0
#define PTP2_PORT_DS_DELAY_MECHANISM                PTP2_DELAY_MECHANISM_E2E
#define PTP2_PORT_DS_LOG_MIN_PDELAY_REQ_INTERVAL    0
#define PTP2_PORT_DS_VERSION_NUMBER                 2
#define PTP2_PORT_DS_ALTERNATE_MASTER                       false
#define PTP2_PORT_DS_PROFILE_SPECIFIC1                      false
#define PTP2_PORT_DS_PROFILE_SPECIFIC2                      false

/* PTPv2 foreign master */
#define PTP2_ANNOUNCE_SEQ_NR_OVERFLOW_WINDOW_SIZE   10      /* Defines the window size for a seq nr overflow has to be an even value*/

/* Node table default values */
#define PTP2_NODE_TABLE_MAX_ENTRIES                     2047    /**< value in maximal number of entries */
#define PTP2_NODE_TABLE_LUT_WRITE_INTERVAL              1000    /**< value in miliseconds */
#define PTP2_NODE_TABLE_CHECK_LEASE_DURATION_INTERVAL   2000    /**< value in miliseconds */

/* Best Master Algorithm */
#define PTP2_BMC_ALGORITHM_PROFILE                          PTP2_BMC_ALGORITHM_PROFILE_DEFAULT

#define PTP2_LOG                                    1
#define PTP2_LOG_TIME_MSEC_HEX                              0
#define PTP2_LOG_LEVEL_MASTER                               PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_PORT                         PTP2_LOG_DEBUG
#define PTP2_LOG_LEVEL_TASK                         PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_TASK_QUEUE                   PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_PACKET                               PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_PACKET_ANALYZER                      PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_PACKET_ASSEMBLER             PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_NODE_TABLE                           PTP2_LOG_DEBUG
#define PTP2_LOG_LEVEL_SHADOW_TABLE                         PTP2_LOG_DEBUG
#define PTP2_LOG_LEVEL_BMC                          PTP2_LOG_INFO
#define PTP2_LOG_LEVEL_HAL                                  PTP2_LOG_INFO

#endif

